Hi Everyone,
Here's my problem: I can't manage to do a proper sort of my ListView! I have set a callback function to sort my ListView, which is correctly called and processed each time I click on the column header of my list, but the result is always incorrect...I have to call my sort function several times in order to have my ListView properly sorted. I'm having a lot of trouble trying to figure this one out, so I decided to present the problem to you all, hoping that someone could see why it doesn't work. I thank you all for your help. I clarify the situation below with some code and an example.
------------------
So, this is my List View and all the operations I do to make it sortable:
// constants for DBE_ObjectList
const string SARR_DUMMY[] = {} //Empty list for creating empty ListView
const int DBE_WIDTH = 200
const int DBE_HEIGHT = 15
DBE DBE_ObjectList = listView(DB_DisplayAllModif, listViewOptionSortText, DBE_WIDTH, DBE_HEIGHT, SARR_DUMMY)
[...]
insertColumn(DBE_ObjectList, 0, "Object List", DBE_WIDTH - 10, null)
set(DBE_ObjectList, 0, doSortAbsoluteNumber)
Basically, I fill my ListView with a list of Object Identifier that have this form: FSS-ADS-X where X is the absolute number (between 1 and 3000). This is the code where I insert those values:
int i = 0 //Index of the list view
Object o
for o in current Module do {
insert(DBE_ObjectList, i++, identifier(o), iconNone)
}
And finally, this is my sort function, which sort the objects by absolute number. Please note that I have tried a lot of sort functions, like this one, but none have shown a correct result, so I don't think the problem come from the sort function:
Regexp rgAbsNo = regexp2 "([0-9]+)$"
int doSortAbsoluteNumber(string s1, string s2)
{
int i1 = 0
int i2 = 0
if (rgAbsNo s1) {
i1 = intOf(s1[match 1])
}
if (rgAbsNo s2) {
i2 = intOf(s2[match 1])
}
if (i1 > i2)
{
return(1)
}
else if (i2 > i1)
{
return(-1)
}
return(0)
}
This is for the code. Now a practical example! This is my initial list:
From this example, I have to call my sort function twice to get it sorted, but if the list is bigger, I have to apply the sort function more. The listView after the first sort:
It is almost sorted, except for the 2190 value which is located before the 2189. The listView after the second sort:
And that's all. I made some debug in my sort function in order to see the evaluation, and this is what I obtain when I do the first sort: i1: 2 < i2:4 i1: 5 < i2:2189 i1: 2190 > i2:5 i1: 2 < i2:5 i1: 4 < i2:5 i1: 2194 > i2:2193 i1: 2191 < i2:2193 i1: 2278 > i2:2256 i1: 2195 < i2:2256 i1: 2191 < i2:2195 i1: 2193 < i2:2195 i1: 2194 < i2:2195 i1: 2 < i2:2191 i1: 4 < i2:2191 i1: 5 < i2:2191 i1: 2190 < i2:2191 i1: 2189 < i2:2191 After the second sort: i1: 2 < i2:4 i1: 2190 > i2:2189 i1: 5 < i2:2189 i1: 2 < i2:5 i1: 4 < i2:5 i1: 2193 < i2:2194 i1: 2191 < i2:2193 i1: 2256 < i2:2278 i1: 2195 < i2:2256 i1: 2191 < i2:2195 i1: 2193 < i2:2195 i1: 2194 < i2:2195 i1: 2 < i2:2191 i1: 4 < i2:2191 i1: 5 < i2:2191 i1: 2189 < i2:2191 i1: 2190 < i2:2191
Once again, I thank you a lot in advance for any help, I am really stuck here and I couldn't find any information anywhere else on this forum and elsewhere. So thank you, and good luck :)
Best Regards, Arnaud
MattMar - Fri Jun 27 10:17:09 EDT 2014 |
Re: Issue when sorting a ListView For reason's I don't know, cannot explain, cannot reproduce, nor convince anybody else of, your "sort" function should not have extraneous code in it.
Inuts are type "string", not sure how that works with a column containing "int". In years past, when I inserted some code into that function I'd often get exception violations when it was invoked by sorting the column, but worked fine when I'd just call it normall. Yes my function takes strings, and yes then "FSS-ADS-4" will sort after "FSS-ADS-2189". Not sure what to do about that. -Louie |
Re: Issue when sorting a ListView llandale - Fri Jun 27 10:47:32 EDT 2014 For reason's I don't know, cannot explain, cannot reproduce, nor convince anybody else of, your "sort" function should not have extraneous code in it.
Inuts are type "string", not sure how that works with a column containing "int". In years past, when I inserted some code into that function I'd often get exception violations when it was invoked by sorting the column, but worked fine when I'd just call it normall. Yes my function takes strings, and yes then "FSS-ADS-4" will sort after "FSS-ADS-2189". Not sure what to do about that. -Louie You could insert Absolute Numbers into your ListView, but turn them into strings by padding with leading spaces.
Using this fPad function:
-Louie |
Re: Issue when sorting a ListView llandale - Fri Jun 27 10:47:32 EDT 2014 For reason's I don't know, cannot explain, cannot reproduce, nor convince anybody else of, your "sort" function should not have extraneous code in it.
Inuts are type "string", not sure how that works with a column containing "int". In years past, when I inserted some code into that function I'd often get exception violations when it was invoked by sorting the column, but worked fine when I'd just call it normall. Yes my function takes strings, and yes then "FSS-ADS-4" will sort after "FSS-ADS-2189". Not sure what to do about that. -Louie Well, as I said, I tried a lot of sort functions, all with the same results. Your code is working, but I still have to perform the sort many times...With my previous example and your sort function, 5 times to be exact. I think it has more to do with the way I Insert my values, maybe a wrong indexation or something....But I'm really not sure, I think like I have tried everything...Well I'll search again! Thank you!
Best Regards, Arnaud
|
Re: Issue when sorting a ListView MattMar - Fri Jun 27 11:11:57 EDT 2014 Well, as I said, I tried a lot of sort functions, all with the same results. Your code is working, but I still have to perform the sort many times...With my previous example and your sort function, 5 times to be exact. I think it has more to do with the way I Insert my values, maybe a wrong indexation or something....But I'm really not sure, I think like I have tried everything...Well I'll search again! Thank you!
Best Regards, Arnaud
I for myself do not have any problems with this routine, but this is, because it was my mistake. I did not know, that this routine exists and so I have sorted the entries first and than filled the listView. May be, that this is a solution here too. ... Best regards Wolfgang |
Re: Issue when sorting a ListView I sporadically experiance the same issue with this code:
int DoSortInt(string sOne, string sTwo)#dw_new_line_replacement#{#dw_new_line_replacement# int iOne = intOf(sOne)#dw_new_line_replacement# int iTwo = intOf(sTwo)#dw_new_line_replacement# if(iOne > iTwo) { return 1 }#dw_new_line_replacement# if(iOne < iTwo) { return -1 }#dw_new_line_replacement# return 0#dw_new_line_replacement#}#dw_new_line_replacement#
I don't know why it sometimes requires multiple clicks to correctly sort a column. It happens always with some scripts and never with others. Maybe it is dependant on the row data but I have not tested. I have never had the exception violation the Louie gets when editing his code, or when using much more complicated sort functions, but something is up with the sort mechanism. You can use it like this:
int DoSortIdentifier(string sOne, string sTwo)#dw_new_line_replacement#{#dw_new_line_replacement# int iOne = intOf(sOne[8:])#dw_new_line_replacement# int iTwo = intOf(sTwo[8:])#dw_new_line_replacement# if(iOne > iTwo) { return 1 }#dw_new_line_replacement# if(iOne < iTwo) { return -1 }#dw_new_line_replacement# return 0#dw_new_line_replacement#}#dw_new_line_replacement#
but it probably wont solve the underlaying problem. -Adam Edit: I give up trying to fix the code formatting... |
Re: Issue when sorting a ListView Wolfgang Uhr - Mon Jun 30 01:53:05 EDT 2014 I for myself do not have any problems with this routine, but this is, because it was my mistake. I did not know, that this routine exists and so I have sorted the entries first and than filled the listView. May be, that this is a solution here too. ... Best regards Wolfgang In my case I need the two sort orders, but maybe if I can't solve the issue I can implement a manual sort function for the list view that allows me to switch between the two sort orders. Thank you! Best regards, Arnaud |
Re: Issue when sorting a ListView Adamarla - Mon Jun 30 04:15:03 EDT 2014 I sporadically experiance the same issue with this code:
int DoSortInt(string sOne, string sTwo)#dw_new_line_replacement#{#dw_new_line_replacement# int iOne = intOf(sOne)#dw_new_line_replacement# int iTwo = intOf(sTwo)#dw_new_line_replacement# if(iOne > iTwo) { return 1 }#dw_new_line_replacement# if(iOne < iTwo) { return -1 }#dw_new_line_replacement# return 0#dw_new_line_replacement#}#dw_new_line_replacement#
I don't know why it sometimes requires multiple clicks to correctly sort a column. It happens always with some scripts and never with others. Maybe it is dependant on the row data but I have not tested. I have never had the exception violation the Louie gets when editing his code, or when using much more complicated sort functions, but something is up with the sort mechanism. You can use it like this:
int DoSortIdentifier(string sOne, string sTwo)#dw_new_line_replacement#{#dw_new_line_replacement# int iOne = intOf(sOne[8:])#dw_new_line_replacement# int iTwo = intOf(sTwo[8:])#dw_new_line_replacement# if(iOne > iTwo) { return 1 }#dw_new_line_replacement# if(iOne < iTwo) { return -1 }#dw_new_line_replacement# return 0#dw_new_line_replacement#}#dw_new_line_replacement#
but it probably wont solve the underlaying problem. -Adam Edit: I give up trying to fix the code formatting... Well, at least I am not an isolated case :) Thank you for the code, but It is sadly still the same problem. I must say though that I never had the exception violation too, no matter the sort function I used. It seems to me that the definition of the Sort function can be very flexible. But regarding my issue and your answers, it seems more and more than the sort function itself is not in cause, and that the problem is more context-dependant. I need to do more tests, I'll post here if I find anything. Best regards, Arnaud |
Re: Issue when sorting a ListView MattMar - Mon Jun 30 04:34:02 EDT 2014 In my case I need the two sort orders, but maybe if I can't solve the issue I can implement a manual sort function for the list view that allows me to switch between the two sort orders. Thank you! Best regards, Arnaud Such a sorting technique is not so difficult as you may thing. Each skiplist created by createString() can do the job for you. You only have to include leading zeros into the strings FDS-ASS-2 -> FDS-ASS-00002 and so on an a put(someSkiplist, "FDS-ASS-00002", objWork) will perform a fast implemented sort. |
Re: Issue when sorting a ListView Wolfgang Uhr - Mon Jun 30 11:33:59 EDT 2014 Such a sorting technique is not so difficult as you may thing. Each skiplist created by createString() can do the job for you. You only have to include leading zeros into the strings FDS-ASS-2 -> FDS-ASS-00002 and so on an a put(someSkiplist, "FDS-ASS-00002", objWork) will perform a fast implemented sort. Yes, you can manually empty the list and repopulate it in any custom order, but it requires extra DBE controls on the GUI to do it which is not so nice. |
Re: Issue when sorting a ListView Adamarla - Tue Jul 01 04:09:48 EDT 2014 Yes, you can manually empty the list and repopulate it in any custom order, but it requires extra DBE controls on the GUI to do it which is not so nice. If you are looking for something "nice", you must not use dxl. |
Re: Issue when sorting a ListView Hello Everyone, Once again, thank you for your help and your interest in my case. I'm here to finally tell you that the problem is solved!!! Or should I say, my ListView is sorted...I can't really explain why except by evoking a bug. The only thing I did was to create a second column to my list view and, all of a sudden, the sort was correctly done... I don't know if it was the fact that I added this column, or the fact that this column was also sortable (with another sort function), but in any case, both columns can now be correctly sorted with a single click, whatever the number of items inserted in the listView. Some DXL Magic!
Best Regards, Arnaud |
Re: Issue when sorting a ListView MattMar - Fri Jul 04 07:27:11 EDT 2014 Hello Everyone, Once again, thank you for your help and your interest in my case. I'm here to finally tell you that the problem is solved!!! Or should I say, my ListView is sorted...I can't really explain why except by evoking a bug. The only thing I did was to create a second column to my list view and, all of a sudden, the sort was correctly done... I don't know if it was the fact that I added this column, or the fact that this column was also sortable (with another sort function), but in any case, both columns can now be correctly sorted with a single click, whatever the number of items inserted in the listView. Some DXL Magic!
Best Regards, Arnaud
Can that new column be sorted when you do not insert the 1st column? I'm still guessing it has something to do with the sort function, somehow inappropriated embedded in something odd. -Louie |
Re: Issue when sorting a ListView llandale - Mon Jul 07 12:26:24 EDT 2014
Can that new column be sorted when you do not insert the 1st column? I'm still guessing it has something to do with the sort function, somehow inappropriated embedded in something odd. -Louie Hi, After some tests, this is the answer to your questions: Can that new column be sorted when you do not insert the 1st column? Yes, but not all at once. It needs several clicks. It is threfore exactly the same results that with only the first column, only the sort function is different. Can the new column be sorted when you define and insert it before the other column? Yes, in this configuration, everythings works. The definition and insertion order of the column does not matter in my case.
I also try to not set a sort function for the second column and it was working for the first column. Arnaud |